<template>
  <ItemInfo title="开票信息" edit @edit="isshow = true">
    <Invoice
      :isshow="isshow"
      @close="isshow = false"
      :list="billingList"
      @updata="updata"
    ></Invoice>
    <template v-if="billingList.length > 0">
      <div class="billingItem" v-for="item in billingList" :key="item.id">
        <div>
          <span>开票头：</span>
          <p>{{ item.invoiceName }}</p>
        </div>
        <div>
          <span>纳税人识别号：</span>
          <p>{{ item.itin }}</p>
        </div>
        <div>
          <span>纳税类型：</span>
          <p>{{ item.type && item.type.desc }}</p>
        </div>
        <div>
          <span>开户名称：</span>
          <p>{{ item.accountName }}</p>
        </div>
        <div>
          <span>开户银行：</span>
          <p>{{ item.bank }}</p>
        </div>
        <div>
          <span>银行账号：</span>
          <p>{{ item.bankAccount }}</p>
        </div>
        <div>
          <span>预留电话：</span>
          <p>{{ item.reservedPhone }}</p>
        </div>
        <div>
          <span>预留地址：</span>
          <p>{{ item.reservedAddress }}</p>
        </div>
      </div>
    </template>
    <template v-else>
      <div class="tishi content">
        <span>提示：</span>
        <p>暂时没有信息</p>
      </div>
    </template>
  </ItemInfo>
</template>

<script>
import Invoice from './invoice'
import {
  addContractSubjectAccountListUpdate,
  editCustomerAccountListUpdate
} from '@/api/human'
export default {
  props: ['list'],
  data() {
    return {
      billingList: [],
      isshow: false,
      path: ''
    }
  },
  watch: {
    list(n) {
      this.billingList = n
    }
  },
  components: {
    Invoice
  },
  methods: {
    // 触发保存
    async updata(form) {
      console.log(form)
      if (form) {
        let data = null
        if (this.path === '/signed/signedlist/info') {
          // 签约主体的修改
          data = await addContractSubjectAccountListUpdate(form)
        } else {
          // 客户管理的修改
          data = await editCustomerAccountListUpdate(form)
        }
        if (data.data) {
          this.$message.success('修改成功！')
        }
      }
      this.$emit('updata')
    }
  },
  created() {
    // 保存路径
    this.path = this.$route.path
  }
}
</script>

<style lang="less" scoped>
.billingItem {
  > div {
    width: 50% !important;
  }
  &:first-child {
    margin-top: 0 !important;
  }
}
</style>
